//提示信息对象
let msg;
//列对象
let cols;
layui.config({
    base: '../lay/dist/'
});
layui.use(['form', 'table', 'laydate', 'notice'], function () {
    var $ = layui.jquery,
        form = layui.form,
        table = layui.table,
        laydate = layui.laydate,
        notice = layui.notice;
    msg = layui.notice;
    /**
     * 表格主题渲染
     */
    table.render({
        elem: '#goodClass',
        url: 'GoodController/weekAndMonth',
        parseData: function (res) {
            return {
                "code": res.success == true ? 0 : 1,
                "count": res.total,
                "data": res.data

            }
        },
        toolbar: '#toolbarDemo',
        defaultToolbar: ['filter', 'exports', 'print', {
            title: '提示',
            layEvent: 'LAYTABLE_TIPS',
            icon: 'layui-icon-tips'
        }],
        cols: [
            [
                {
                    field: 'xid', title: '序号', sort: true, templet: function (d) {
                        return d.LAY_INDEX;
                    }
                },


                {field: 'className', title: '班级', width: 100},
                {
                    field: 'checkClassWork', title: '查班出勤率', templet: function (result) {
                        if (result.checkClassWork < 90) {
                            return "<span class='iconfont icon-jinggao' style='color: red'>" + result.checkClassWork + "</span>"
                        } else {
                            return "<span class='iconfont icon-custom-ok' style='color: #61bc56'>" + result.checkClassWork + "</span>"
                        }

                    }
                },
                {
                    field: 'formalWork', title: '正装率', templet: function (result) {
                        if (result.formalWork < 90) {
                            return "<span class='iconfont icon-jinggao' style='color: red'>" + result.formalWork + "</span>"
                        } else {
                            return "<span class='iconfont icon-custom-ok' style='color: #61bc56'>" + result.formalWork + "</span>"
                        }

                    }
                },
                {
                    field: 'checkHealthScore', title: '卫生打扫平均分', templet: function (result) {
                        if (result.checkHealthScore < 15) {
                            return "<span class='iconfont icon-jinggao' style='color: red'>" + result.checkHealthScore + "</span>"
                        } else {
                            return "<span class='iconfont icon-custom-ok' style='color: #61bc56'>" + result.checkHealthScore + "</span>"
                        }

                    }
                },

                {
                    field: 'checkMorningWork', title: '晨练出勤率', templet: function (result) {
                        if (result.checkMorningWork < 90) {
                            return "<span class='iconfont icon-jinggao' style='color: red'>" + result.checkMorningWork + "</span>"
                        } else {
                            return "<span class='iconfont icon-custom-ok' style='color: #61bc56'>" + result.checkMorningWork + "</span>"
                        }

                    }
                },
                {
                    field: 'sum', title: '总分', templet: function (result) {
                        return parseInt(result.checkMorningWork) +
                            parseInt(result.checkHealthScore)
                            + parseInt(result.formalWork)
                            + parseInt(result.checkClassWork);

                    }
                },

                {
                    field: 'checkHealthIsRed', title: '卫生标红次数', templet: function (result) {
                        if (result.checkHealthIsRed >= 1) {
                            return "<span class='iconfont icon-jinggao' style='color: red'>" + result.checkHealthIsRed + "</span>"
                        } else {
                            return "<span class='iconfont icon-custom-ok' style='color: #61bc56'>" + result.checkHealthIsRed + "</span>"
                        }

                    }
                },

                {
                    field: 'checkEveningIsRed', title: '晚自习标红次数', templet: function (result) {
                        if (result.checkEveningIsRed > 1) {
                            return "<span class='iconfont icon-jinggao' style='color: red'>" + result.checkEveningIsRed + "</span>"
                        } else {
                            return "<span class='iconfont icon-custom-ok' style='color: #61bc56'>" + result.checkEveningIsRed + "</span>"
                        }

                    }
                },


                {
                    field: 'checkDormScore', title: '宿舍平均分数', templet: function (result) {
                        if (result.checkDormScore < 60) {
                            return "<span class='iconfont icon-jinggao' style='color: red'>" + result.checkDormScore + "</span>"
                        } else {
                            return "<span class='iconfont icon-custom-ok' style='color: #61bc56'>" + result.checkDormScore + "</span>"
                        }

                    }
                },


                {field: 'teacherName', title: '班级老师'},

            ]
        ],
        limits: [10, 15, 20, 25, 50, 100],
        limit: 15,
        page: true,
        skin: 'line'
    });
    /**
     * 监听搜索操作
     */
    form.on('submit(data-search-btn)', function (data) {
        var result = data.field;
        console.log(result)
        //执行搜索重载
        table.reload('goodClass', {
            url: 'GoodController/weekAndMonth'
            , where: {
                beginTime: result.beginTime,
                endTime: result.endTime1
            }
        }, 'data');
        notice.success("搜索执行成功！");

        return false;
    });

    form.on('submit(goodClass)', function (data) {
        var result = data.field;
        console.log(result)
        //执行搜索重载
        table.reload('goodClass', {
            url: 'GoodController/goodClass'
            , where: {
                isRed:result.isRed,
                work:result.work,
                beginTime:result.beginTime2,
                endTime:result.endTime2,
            }
        }, 'data');
        notice.success("搜索执行成功！");

        return false;
    });

    /**
     * 时间选择器自定义颜色
     */
    laydate.render({
        elem: '#begin1'
        , theme: '#393D49'
    });
    /**
     * 时间选择器自定义颜色
     */
    laydate.render({
        elem: '#end1'
        , theme: '#393D49'
    });

    laydate.render({
        elem: '#end2'
        , theme: '#393D49'
    });

    laydate.render({
        elem: '#begin2'
        , theme: '#393D49'
    });
    /**
     * 设置提示信息属性
     * @type {{hideEasing: string, positionClass: string, hideDuration: string, debug: boolean, closeButton: boolean, extendedTimeOut: string, showEasing: string, onclick: null, showDuration: string, iconClass: string, timeOut: string}}
     */
    notice.options = {
        closeButton: true,//显示关闭按钮
        debug: false,//启用debug
        positionClass: "toast-bottom-right",//弹出的位置,
        showDuration: "300",//显示的时间
        hideDuration: "1000",//消失的时间
        timeOut: "2000",//停留的时间
        extendedTimeOut: "1000",//控制时间
        showEasing: "swing",//显示时的动画缓冲方式
        hideEasing: "linear",//消失时的动画缓冲方式
        iconClass: 'toast-info', // 自定义图标，有内置，如不需要则传空 支持layui内置图标/自定义iconfont类名
        onclick: null, // 点击关闭回调
    };

    // notice.warning("");信息状态
    // notice.info("");
    // notice.error("");
    // notice.success("");
});

/**
 * 子窗体编辑后父窗体动态改变
 * @param result
 * @param childData
 */
function parentPage(result, childData) {

    if (result.success == true) {
        cols.update({
            date: childData.beginTime,
            istop: childData.isTop,
            classRoomName: childData.classRoomName,
            className: childData.className,
            factPersons: childData.factPersons,
            work: childData.factPersonsWork,
            formalsuit: childData.formalsuit,
            formalwork: childData.formalwork,
            studentName: childData.studentName
        })

        msg.info("修改成功");
        return;
    }
    msg.warning("修改失败")

}
